package com.task.utils;   
  
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletContextEvent;   
import javax.servlet.ServletContextListener;   
 
public class StatisticsContextListener implements ServletContextListener   
{   
  
    private java.util.Timer timer = null;   
    
    public void contextInitialized(ServletContextEvent event)    
    {    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
    //定制每天的21:09:00执行，
    calendar.set(year, month, day, 23, 59, 15);
    Date date = calendar.getTime();
        timer = new java.util.Timer(true);   
        event.getServletContext().log("定时器已启动");    
        timer.schedule(new StatisticsTask(event.getServletContext()), date);  
        event.getServletContext().log("已经添加任务调度表");   
    }   
       
       
    public void contextDestroyed(ServletContextEvent event)   
    {   
        timer.cancel();   
        event.getServletContext().log("定时器销毁");   
    }   
  
}  
